﻿using System;
using System.Linq;
using Microsoft.Win32;

namespace MLogix
{
    sealed public class NotificationControl
    {

        static RegistryKey notificationReg = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("MLogix").CreateSubKey("Rules"); 

        static public bool GetStatus()
        {
            return bool.Parse(notificationReg.GetValue("NStatus", bool.FalseString).ToString());
        }

        static public bool GetMode()
        {
            return bool.Parse(notificationReg.GetValue("NMode", bool.TrueString).ToString());
        }

        static public bool SetLoudMode()
        {
            notificationReg.SetValue("NMode", bool.FalseString);
            notificationReg.Flush();
            return false;
        }

        static public bool SetSilentMode()
        {
            notificationReg.SetValue("NMode", bool.TrueString);
            notificationReg.Flush();
            return true;
        }

        static public bool Enable()
        {
            notificationReg.SetValue("NStatus", bool.TrueString);
            notificationReg.Flush();

            return true;
        }

        static public bool Disable()
        {
            notificationReg.SetValue("NStatus", bool.FalseString);
            notificationReg.Flush();
         
            return false;
        }

        static public void ChangeMessage(string message)
        {
            notificationReg.SetValue("NMessage", message.Replace("\"","'"));
            notificationReg.Flush();
        }

        static public string GetMessage()
        {
            return notificationReg.GetValue("NMessage", "You got mail ;)").ToString();
        }

        static public string GetFilterPath()
        {
            return notificationReg.GetValue("AppPath").ToString().Replace("Saver.exe", "SMSFilter.exe");
        }

        static public bool GetQuickStartMode()
        {
            return bool.Parse(notificationReg.GetValue("QStart", bool.FalseString).ToString());
        }

        static public bool EnableQuickStartMode()
        {
            notificationReg.SetValue("QStart", bool.TrueString);
            notificationReg.Flush();

            return true;
        }

        static public bool DisableQuickStartMode()
        {
            notificationReg.SetValue("QStart", bool.FalseString);
            notificationReg.Flush();

            return false;
        }

        static public bool GetReadMode()
        {
            bool mode = false;
            mode = bool.Parse(notificationReg.GetValue("Read", bool.FalseString).ToString());
            notificationReg.SetValue("Read", bool.FalseString);
            notificationReg.Flush();
            return mode;

        }

        static public bool IsNewMessageAvailable(out string contact)
        {
            bool available = false;
            contact = notificationReg.GetValue("NewMessageFrom", bool.FalseString).ToString().Trim();
            if (string.IsNullOrEmpty(contact))
            {
                available = false;
            }
            else
            {
                available = true;
            }
            notificationReg.SetValue("NewMessageFrom", string.Empty);
            notificationReg.Flush();
            return available;
        }

        static public void SetNewMessageContact(string contact)
        {
            notificationReg.SetValue("NewMessageFrom", contact);
            notificationReg.Flush();
        }

        static public bool GetSaveSentMode()
        {
            bool mode = false;
            mode = bool.Parse(notificationReg.GetValue("SaveSent", bool.FalseString).ToString());
            notificationReg.Flush();
            return mode;
        }

        static public bool SetSaveSentMode(bool mode)
        {
            notificationReg.SetValue("SaveSent", mode.ToString());
            notificationReg.Flush();
            return mode;
        }


        static public bool GetDeliveryMode()
        {
            bool mode = false;
            mode = bool.Parse(notificationReg.GetValue("SentAlert", bool.FalseString).ToString());
            notificationReg.Flush();
            return mode;
        }

        static public bool SetDeliveryMode(bool mode)
        {
            notificationReg.SetValue("SentAlert", mode.ToString());
            notificationReg.Flush();
            return mode;
        }

    }
}